package User;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * JDBC快速入门
 */
public class a {

    public static void main(String[] args) throws Exception {
        //1. 注册驱动
        //Class.forName("com.mysql.cj.jdbc.Driver");
        //2. 获取连接
        try{
            String url = "jdbc:mysql://localhost:3306/ai?serverTimezone=Asia/Shanghai";
            String username = "root";
            String password = "123456";
            Connection conn = DriverManager.getConnection(url, username, password);
            //3. 定义sql
            String sql = "INSERT INTO users (username, password) VALUES ('bbbbbb', '4567');";
            //4. 获取执行sql的对象 Statement
            Statement stmt = conn.createStatement();
            //5. 执行sql
            int count = stmt.executeUpdate(sql);//受影响的行数
            //6. 处理结果
            System.out.println(count);
            //7. 释放资源
            stmt.close();
            conn.close();
        }catch (Exception e){
            System.out.println(" ");
        }


    }
}
